<template>
  <div id="main" style="width: 100%; height: 100%"></div>
</template>

<script>
import * as echarts from "echarts";
require("echarts/theme/macarons"); // echarts theme
import resize from "../../dashboard/mixins/resize";

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '300px'
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')

      this.chart.setOption ({
        title: {
          text: '供水保证率'
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            label: {
              backgroundColor: '#6a7985'
            }
          }
        },
        // legend: {
        //   data: ['Email', 'Union Ads', 'Video Ads', 'Direct', 'Search Engine']
        // },
        // toolbox: {
        //   feature: {
        //     saveAsImage: {}
        //   }
        // },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [
          {
            type: 'category',
            boundaryGap: false,
            data: ['2016', '2017', '2018', '2019', '2020']
          }
        ],
        yAxis: [
          {
            type: 'value',
            min: 80,
            max: 100
          }
        ],
        series: [
          {
            name: '供水保证率',
            type: 'line',
            stack: 'Total',
            emphasis: {
              focus: 'series'
            },
            areaStyle: {
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                {
                  offset: 0,
                  color: 'rgba(58,77,233,0.8)'
                },
                {
                  offset: 1,
                  color: 'rgba(58,77,233,0.001)'
                }
              ])
            },
            markLine: {
              symbol: ['none', 'none'], // none为标线两端的样式为无，可更改
              data: [
                {
                  silent: false,
                  yAxis: 95,  // 警戒线位置，这个赋值为纵轴50
                  // label: {
                  //   position: 'end', // 文字位置
                  //   formatter: '标准供给时长',  //文字
                  //   color: 'green'  // 文字颜色
                  // },
                  lineStyle: { type: 'dashed', color: 'white', width: 2 } // 样式： 线型、颜色、线宽
                }
              ]
            },
            data: [87, 88, 90, 97, 89]
          }
        ]
      });
    }
  }
}
</script>

